<template>
  <div class="myCollBox" v-loading='loading'>
    <div class="tabsBox">
      <span :class="selTab===1?'selTabs':''" @click="tabsClick(1)">课堂（{{spTotal}}）</span>
      <span :class="selTab===2?'selTabs':''" @click="tabsClick(2)">回答（{{total}}）</span>
    </div>
    <div class="w1200" v-if="selTab===1">
      <div class="indexList2">
        <div class="indexItem2" v-for="(item,index) in spArr" :key="index" @click="spxqClick(item.id)">
          <div class="imgbox2">
            <img :src="item.headUrl" alt="" srcset="" class="indexImg"/>
            <span class="time">{{item.videoDuration}}</span>
          </div>
          <div class="indexCon">
            <h3>{{item.videoTitle}}</h3>
            <div class="indexText3" v-for="tag in item.tags" :key="tag">{{item.classifyNames}}</div>
            <div class="betweens">
              <div class="col4">收藏于 {{item.createDate}}</div>
              <!-- <div class="collection" @click="collectionClick(item.id)">
                <img :src="iscollection? require('../../assets/img/collection1.png'):require('../../assets/img/collection2.png')" style="width:25px" alt="">
                <span :style="{color:iscollection?'#AAAAAA':'#f59a23'}" class="abc">&ensp;{{datas.videoFavorites}}</span>
              </div> -->
            </div>
          </div>
        </div>
      </div>
      <div class="pagination">
        <el-pagination
          :current-page="spPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="spLimit"
          :total="spTotal"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageKcSizeChangeHandle"
          @current-change="pageKcCurrentChangeHandle">
        </el-pagination>
      </div>
    </div>
    <div class="questionAnswerMain" v-else>
      <div class="questionAnswerMainLeft">
        <div class="questionAnswerContent">
          <div class="questionAnswerList" v-for="(item,index) in dataList" :key="index">
            <div class="questionAnswerTitle">
              <i class="el-icon-question" style="color:#26b000;font-size:20px"></i>
              <span>{{item.qtitle}}</span>
            </div>
            <div class="titleInformation">
              <div class="titleInformationTitle">
                <span v-for="(aitem,aindex) in item.labelList" :key="aindex">{{aitem.labelName}}</span>
              </div>
              <div class="statistics">
                <span>{{item.createDate}}</span>
                <span>{{item.readNum===null?0:item.readNum}}人阅读</span>
                <span>{{item.interestNum===null?0:item.interestNum}}人关注</span>
              </div>
            </div>
            <div class="expertInformation" v-if="item.allAnswerList.length!==0">
              <div class="expertAvatar">
                <img v-if="item.allAnswerList[0].tbExpertDTO.publicityPhotos===null" src="../../assets/img/zjtj.png" alt="">
                <img v-else :src="item.allAnswerList[0].tbExpertDTO.publicityPhotos" alt="">
              </div>
              <div class="expertIntroduction">
                <div class="expertName">
                  <span>{{item.allAnswerList[0].tbExpertDTO.expertName}}</span>
                  <span v-html="item.allAnswerList[0].acontent"></span>
                </div>
              </div>
            </div>
            <div v-else style="text-align:center;color:#ccc;margin:20px 0;">暂无回答</div>
            <div class="favoriteLikes">
              <div class="favoriteLikesGroup">
                <div class="collection" @click.stop="collectOrNiceAnswer(item.allAnswerList[0].id,0,item.allAnswerList[0].collectFlag)">
                  <img :src="item.allAnswerList[0].collectFlag===0? require('../../assets/img/collection1.png'):require('../../assets/img/collection2.png')" style="width:20px" alt="">
                  <span :style="{color:item.allAnswerList[0].collectFlag===0?'#AAAAAA':'#f59a23'}">{{item.allAnswerList[0].collectNum===null?0:item.allAnswerList[0].collectNum}}</span>
                </div>
                <div class="likesNumber" @click.stop="collectOrNiceAnswer(item.allAnswerList[0].id,1,item.allAnswerList[0].niceFlag)">
                  <img :src="item.allAnswerList[0].niceFlag===0?require('../../assets/img/fabulous1.png'):require('../../assets/img/fabulous2.png')" style="width:20px" alt="">
                  <span :style="{color:item.allAnswerList[0].niceFlag===0?'#AAAAAA':'#f59a23'}">{{item.allAnswerList[0].niceNum===null?0:item.allAnswerList[0].niceNum}}</span>
                </div>
              </div>
              <div class="more">
                <el-button type="text">展开</el-button>
              </div>
            </div>
            <el-divider></el-divider>
          </div>
          <div class="pagination">
            <el-pagination
              :current-page="page"
              :page-sizes="[10, 20, 50, 100]"
              :page-size="limit"
              :total="total"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="pageSizeChangeHandle"
              @current-change="pageCurrentChangeHandle">
            </el-pagination>
          </div>
        </div>
      </div>
      <div class="questionAnswerMainRight" @click="consultImmediately">
        <div class="questionAnswerMainRightContent">
          <div class="consultImmediatelyButton">
          </div>
          <img src="../../assets/img/consultImmediately.png" alt="">
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { dataJson2 } from './data.js'
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      selTab: 1,
      dataJson2,
      questionAnswerList: [],
      loading: false,
      spPage: 1,
      spLimit: 10,
      spTotal: 0,
      spArr: [],
      mixinViewModuleOptions: {
        getDataListURL: '/xnkt/tbquestionkt/myQuestionPage',
        getDataListIsPage: true
      },
      dataForm: {},
      iscollection: false
    }
  },
  props: ['type'],
  mounted () {
    window.scrollTo(0, 0)
  },
  created () {
    this.init()
  },
  methods: {
    init () {
      this.$set(this.dataForm, 'selectType', this.type)
      this.getDataList()
      if (this.type === 2) {
        this.getScKc()
      } else {
        this.getDzKc()
      }
    },
    // 切换tab
    tabsClick (num) {
      this.selTab = num
    },
    // 获取收藏课程列表
    getScKc () {
      this.loading = true
      let params = {
        spPage: 1,
        spLimit: 10
      }
      this.$http.get(`/xnkt/tbvideofavorites/myFavoritesPage`, { params }).then(({ data: res }) => {
        if (res.code !== 0) {
          this.loading = false
          return this.$message.error(res.msg)
        }
        this.spArr = res.data.list
        this.spTotal = res.data.total
        this.loading = false
      }).catch(() => { this.loading = false })
    },
    // 获取点赞课程列表
    getDzKc () {
      this.loading = true
      let params = {
        spPage: 1,
        spLimit: 10
      }
      this.$http.get(`/xnkt/tbvideolikes/myLikePage`, { params }).then(({ data: res }) => {
        if (res.code !== 0) {
          this.loading = false
          return this.$message.error(res.msg)
        }
        this.spArr = res.data.list
        this.spTotal = res.data.total
        this.loading = false
      }).catch(() => { this.loading = false })
    },
    // 分页, 每页条数
    pageKcSizeChangeHandle (val) {
      this.spPage = 1
      this.spLimit = val
      this.getDataList()
    },
    // 分页, 当前页
    pageKcCurrentChangeHandle (val) {
      this.spPage = val
      this.getScKc()
    },
    // 点击课程
    spxqClick (id) {
      console.info(id)
      this.$router.push({
        name: 'classroomview',
        query: { id }
      })
    },
    // 立即咨询
    consultImmediately () {
      this.$router.push({ name: 'consultingService' })
    },
    // 切换问答点赞收藏
    collectOrNiceAnswer (id, type, optType) {
      this.loading = true
      if (optType === 0) {
        optType = 1
      } else {
        optType = 0
      }
      this.$http.get(`/xnkt/tbquestionkt/collectOrNiceAnswer/${id}/${type}/${optType}`).then(({ data: res }) => {
        if (res.code !== 0) {
          this.loading = false
          return this.$message.error(res.msg)
        }
        this.typeList = res.data
        this.lId = res.data[0].id
        this.getDataList()
      }).catch(() => { this.loading = false })
    }
  }
}
</script>
<style lang="scss" src="./index.scss" scoped></style>
